/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mlbs.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author mckd87
 */
@Entity
@Table(name = "usertable")
@NamedQueries({@NamedQuery(name = "Usertable.findByActive", query = "SELECT u FROM Usertable u WHERE u.active = :active"), @NamedQuery(name = "Usertable.findByAgeId", query = "SELECT u FROM Usertable u WHERE u.ageId = :ageId"), @NamedQuery(name = "Usertable.findByBirthday", query = "SELECT u FROM Usertable u WHERE u.birthday = :birthday"), @NamedQuery(name = "Usertable.findByEmailid", query = "SELECT u FROM Usertable u WHERE u.emailid = :emailid"), @NamedQuery(name = "Usertable.findByChallengeAnswer", query = "SELECT u FROM Usertable u WHERE u.challengeAnswer = :challengeAnswer"), @NamedQuery(name = "Usertable.findByDateCreated", query = "SELECT u FROM Usertable u WHERE u.dateCreated = :dateCreated"), @NamedQuery(name = "Usertable.findByDateModified", query = "SELECT u FROM Usertable u WHERE u.dateModified = :dateModified"), @NamedQuery(name = "Usertable.findByDisplayName", query = "SELECT u FROM Usertable u WHERE u.displayName = :displayName"), @NamedQuery(name = "Usertable.findByFirstName", query = "SELECT u FROM Usertable u WHERE u.firstName = :firstName"), @NamedQuery(name = "Usertable.findByLastName", query = "SELECT u FROM Usertable u WHERE u.lastName = :lastName"), @NamedQuery(name = "Usertable.findByOptionFlags", query = "SELECT u FROM Usertable u WHERE u.optionFlags = :optionFlags"), @NamedQuery(name = "Usertable.findBySubscriptionID", query = "SELECT u FROM Usertable u WHERE u.subscriptionID = :subscriptionID"), @NamedQuery(name = "Usertable.findByUserId", query = "SELECT u FROM Usertable u WHERE u.userId = :userId")})
public class Usertable implements Serializable {
    private static final long serialVersionUID = 1L;
    @Column(name = "active", nullable = false)
    private char active;
    @Column(name = "ageId")
    private Integer ageId;
    @Column(name = "birthday")
    @Temporal(TemporalType.DATE)
    private Date birthday;
    @Column(name = "emailid")
    private String emailid;
    @Column(name = "challengeAnswer")
    private String challengeAnswer;
    @Column(name = "dateCreated", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date dateCreated;
    @Column(name = "dateModified", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date dateModified;
    @Column(name = "displayName", nullable = false)
    private String displayName;
    @Column(name = "firstName")
    private String firstName;
    @Column(name = "lastName")
    private String lastName;
    @Column(name = "optionFlags", nullable = false)
    private int optionFlags;
    @Column(name = "subscriptionID", nullable = false)
    private String subscriptionID;
    @Id
    @Column(name = "userId", nullable = false)
    private Integer userId;
    @OneToMany(mappedBy = "userId")
    private Collection<Invoice> invoiceCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "userid")
    private Collection<Devicelocation> devicelocationCollection;
    @JoinColumn(name = "challengeId", referencedColumnName = "challengeId")
    @ManyToOne
    private Challengequestion challengeId;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "usertable")
    private Credential credential;
    @OneToMany(mappedBy = "userid", fetch=FetchType.EAGER)
    private Collection<Device> deviceCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "userId", fetch=FetchType.EAGER)
    private Collection<Appusage> appusageCollection;
    @OneToMany(mappedBy = "userId", fetch=FetchType.EAGER)
    private Collection<Preferences> preferencesCollection;

    public Usertable() {
        preferencesCollection = new ArrayList<Preferences>();
        deviceCollection = new ArrayList<Device>();
        appusageCollection = new ArrayList<Appusage>();
    }

    public Usertable(Integer userId) {
        this.userId = userId;
        preferencesCollection = new ArrayList<Preferences>();
        deviceCollection = new ArrayList<Device>();
        appusageCollection = new ArrayList<Appusage>();
    }

    public Usertable(Integer userId, char active, Date dateCreated, Date dateModified, String displayName, int optionFlags, String subscriptionID) {
        this.userId = userId;
        this.active = active;
        this.dateCreated = dateCreated;
        this.dateModified = dateModified;
        this.displayName = displayName;
        this.optionFlags = optionFlags;
        this.subscriptionID = subscriptionID;
    }

    public char getActive() {
        return active;
    }

    public void setActive(char active) {
        this.active = active;
    }

    public Integer getAgeId() {
        return ageId;
    }

    public void setAgeId(Integer ageId) {
        this.ageId = ageId;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getEmailid() {
        return emailid;
    }

    public void setEmailid(String emailid) {
        this.emailid = emailid;
    }

    public String getChallengeAnswer() {
        return challengeAnswer;
    }

    public void setChallengeAnswer(String challengeAnswer) {
        this.challengeAnswer = challengeAnswer;
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public Date getDateModified() {
        return dateModified;
    }

    public void setDateModified(Date dateModified) {
        this.dateModified = dateModified;
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public int getOptionFlags() {
        return optionFlags;
    }

    public void setOptionFlags(int optionFlags) {
        this.optionFlags = optionFlags;
    }

    public String getSubscriptionID() {
        return subscriptionID;
    }

    public void setSubscriptionID(String subscriptionID) {
        this.subscriptionID = subscriptionID;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public Collection<Invoice> getInvoiceCollection() {
        return invoiceCollection;
    }

    public void setInvoiceCollection(Collection<Invoice> invoiceCollection) {
        this.invoiceCollection = invoiceCollection;
    }

    public Collection<Devicelocation> getDevicelocationCollection() {
        return devicelocationCollection;
    }

    public void setDevicelocationCollection(Collection<Devicelocation> devicelocationCollection) {
        this.devicelocationCollection = devicelocationCollection;
    }

    public Challengequestion getChallengeId() {
        return challengeId;
    }

    public void setChallengeId(Challengequestion challengeId) {
        this.challengeId = challengeId;
    }

    public Credential getCredential() {
        return credential;
    }

    public void setCredential(Credential credential) {
        this.credential = credential;
    }

    public Collection<Device> getDeviceCollection() {
        return deviceCollection;
    }

    public void setDeviceCollection(Collection<Device> deviceCollection) {
        this.deviceCollection = deviceCollection;
    }

    public Collection<Appusage> getAppusageCollection() {
        return appusageCollection;
    }

    public void setAppusageCollection(Collection<Appusage> appusageCollection) {
        this.appusageCollection = appusageCollection;
    }

    
    public Collection<Preferences> getPreferencesCollection() {
        return preferencesCollection;
    }

    public void setPreferencesCollection(Collection<Preferences> preferencesCollection) {
        this.preferencesCollection = preferencesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userId != null ? userId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Usertable)) {
            return false;
        }
        Usertable other = (Usertable) object;
        if ((this.userId == null && other.userId != null) || (this.userId != null && !this.userId.equals(other.userId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.mlbs.entity.Usertable[userId=" + userId + "]";
    }

}
